package cn.iocoder.yudao.module.famous.doctor.controller.admin.diseaseLabel;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.famous.doctor.controller.admin.diseaseLabel.vo.*;
import cn.iocoder.yudao.module.famous.doctor.dal.dataobject.diseaseLabel.DiseaseLabelDO;
import cn.iocoder.yudao.module.famous.doctor.convert.diseaseLabel.DiseaseLabelConvert;
import cn.iocoder.yudao.module.famous.doctor.service.diseaseLabel.DiseaseLabelService;

@Tag(name = "管理后台 - 疾病标签")
@RestController
@RequestMapping("/famous.doctor/disease-label")
@Validated
public class DiseaseLabelController {

    @Resource
    private DiseaseLabelService diseaseLabelService;

    @PostMapping("/create")
    @Operation(summary = "创建疾病标签")
    @PreAuthorize("@ss.hasPermission('famous.doctor:disease-label:create')")
    public CommonResult<Long> createDiseaseLabel(@Valid @RequestBody DiseaseLabelCreateReqVO createReqVO) {
        return success(diseaseLabelService.createDiseaseLabel(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新疾病标签")
    @PreAuthorize("@ss.hasPermission('famous.doctor:disease-label:update')")
    public CommonResult<Boolean> updateDiseaseLabel(@Valid @RequestBody DiseaseLabelUpdateReqVO updateReqVO) {
        diseaseLabelService.updateDiseaseLabel(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除疾病标签")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('famous.doctor:disease-label:delete')")
    public CommonResult<Boolean> deleteDiseaseLabel(@RequestParam("id") Long id) {
        diseaseLabelService.deleteDiseaseLabel(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得疾病标签")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('famous.doctor:disease-label:query')")
    public CommonResult<DiseaseLabelRespVO> getDiseaseLabel(@RequestParam("id") Long id) {
        DiseaseLabelDO diseaseLabel = diseaseLabelService.getDiseaseLabel(id);
        return success(DiseaseLabelConvert.INSTANCE.convert(diseaseLabel));
    }

    @GetMapping("/list")
    @Operation(summary = "获得疾病标签列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('famous.doctor:disease-label:query')")
    public CommonResult<List<DiseaseLabelRespVO>> getDiseaseLabelList(@RequestParam("ids") Collection<Long> ids) {
        List<DiseaseLabelDO> list = diseaseLabelService.getDiseaseLabelList(ids);
        return success(DiseaseLabelConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/listAll")
    @Operation(summary = "获得疾病标签列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('famous.doctor:disease-label:queryAll')")
    public CommonResult<List<DiseaseLabelRespVO>> getDiseaseLabelLisAll(@Valid DiseaseLabelExportReqVO createReqVO) {
        List<DiseaseLabelDO> list = diseaseLabelService.getDiseaseLabelLisAll(createReqVO);
        return success(DiseaseLabelConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得疾病标签分页")
    @PreAuthorize("@ss.hasPermission('famous.doctor:disease-label:query')")
    public CommonResult<PageResult<DiseaseLabelRespVO>> getDiseaseLabelPage(@Valid DiseaseLabelPageReqVO pageVO) {
        PageResult<DiseaseLabelDO> pageResult = diseaseLabelService.getDiseaseLabelPage(pageVO);
        return success(DiseaseLabelConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出疾病标签 Excel")
    @PreAuthorize("@ss.hasPermission('famous.doctor:disease-label:export')")
    @OperateLog(type = EXPORT)
    public void exportDiseaseLabelExcel(@Valid DiseaseLabelExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<DiseaseLabelDO> list = diseaseLabelService.getDiseaseLabelList(exportReqVO);
        // 导出 Excel
        List<DiseaseLabelExcelVO> datas = DiseaseLabelConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "疾病标签.xls", "数据", DiseaseLabelExcelVO.class, datas);
    }

}
